package transcation;

import org.apache.activemq.ActiveMQTopicSession;
import org.apache.activemq.ActiveMQXAConnection;
import org.apache.activemq.ActiveMQXAConnectionFactory;

import javax.jms.*;

/**
 * Created with Intel IDEA.
 *
 * @Auther: gjt
 * @Date: 2024/11/16 9:15
 */
public class test {
    public static void main(String[] args) {
        try {
            // 1.事务性链接工厂
            XAConnectionFactory xaConnectionFactory = new ActiveMQXAConnectionFactory();
            // 2.事务性链接
            XAConnection xaConnection = xaConnectionFactory.createXAConnection();
            // 3.事务性会话
            XASession xaSession = xaConnection.createXASession();

            // 3.事务性队列链接工厂
            XAQueueConnectionFactory xaQueueConnectionFactory = new ActiveMQXAConnectionFactory();
            // 4.事务性队列链接
            XAQueueConnection xaQueueConnection = xaQueueConnectionFactory.createXAQueueConnection();
            // 5.事务性队列会话
            QueueSession queueSession = xaQueueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

            // 6.事务性主题链接工厂
            XATopicConnectionFactory xaTopicConnectionFactory = new ActiveMQXAConnectionFactory();
            // 7.事务性主题链接
            XATopicConnection xaTopicConnection = xaTopicConnectionFactory.createXATopicConnection();
            // 8.事务性主题会话
            TopicSession topicSession = xaTopicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
